﻿using AutoMapper;
using B.S.BaseData.Domain;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.Infrastructure.Interfaces;
using B.S.BaseData.ReadAPI.Applications.Commands.AccountCommand;
using B.S.BaseData.ReadAPI.Dtos;
using Consul;
using MD5Hash;
using MediatR;
using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;
using System.Text;

namespace B.S.BaseData.ReadAPI.Applications.CommandHandlers.AccountCommandHandler
{
    public class GetAccountHandler : IRequestHandler<GetAccountCommand, ApiResult<List<Account>>>
    {
        IBaseRepository<Account> accountrepositoy;
        ILogger<LoginHandler> logger;
        IMapper mapper;
        private readonly TokenHelper tokenHelper;

        public GetAccountHandler(IBaseRepository<Account> accountrepositoy, ILogger<LoginHandler> logger, IMapper mapper, TokenHelper tokenHelper)
        {
            this.accountrepositoy = accountrepositoy;
            this.logger = logger;
            this.mapper = mapper;
            this.tokenHelper = tokenHelper;
        }

        public async Task<ApiResult<List<Account>>> Handle(GetAccountCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var list = await accountrepositoy.Query(x=>x.IsDelete==0).ToListAsync(cancellationToken);



                return new ApiResult<List<Account>>()
                {
                    data = list,
                    msg = "查询成功",
                    IsSuc = true
                };
            }
            catch (Exception ex)
            {
                logger.LogError("查询出错" + ex.Message);
                throw;
            }
        }


    }
}
